//
//  MALView.swift
//  Swift_Study
//
//  Created by wangtian on 15/7/23.
//  Copyright (c) 2015年 wangtian. All rights reserved.
//

import Foundation
import UIKit

let MNotSet = CGFloat.greatestFiniteMagnitude

extension UIView{

    //MARK: 设置frame
    /**
    设置frame
    
    :param: X      横坐标  不设置传入MNotSet
    :param: Y      纵坐标  不设置传入MNotSet
    :param: Width  宽度    不设置传入MNotSet
    :param: Height 高度    不设置传入MNotSet
    */
    func setViewFrameWithX(_ X:CGFloat, Y:CGFloat, Width:CGFloat, Height:CGFloat) -> Void{
    
        var viewFrame = self.frame
        
        if X != MNotSet
        {
           viewFrame.origin.x = X
        }
        
        if Y != MNotSet
        {
            viewFrame.origin.y = Y
        }
        
        if Width != MNotSet
        {
            viewFrame.size.width = Width
        }
        
        if Height != MNotSet
        {
            viewFrame.size.height = Height
        }

        self.frame = viewFrame
    }
    
    func setPointX(_ X:CGFloat ,Y:CGFloat)
    {
        self.setViewFrameWithX(X, Y: Y, Width: MNotSet, Height: MNotSet)
    }
    
    //MARK: 设置横坐标
    func setX(_ X:CGFloat)
    {
        self.setPointX(X, Y: MNotSet)
    }
    
    func setY(_ Y:CGFloat)
    {
        self.setPointX(MNotSet, Y: Y)
    }
    
    func setSizeWidth(_ mWidth:CGFloat, mHeight:CGFloat) -> Void
    {
        self.setViewFrameWithX(MNotSet, Y: MNotSet, Width: mWidth, Height: mHeight)
    }
    
    func setWidth(_ Width:CGFloat)
    {
        self.setSizeWidth(Width, mHeight: MNotSet)
    }
    
    func setHeight(_ Height:CGFloat)
    {
        self.setSizeWidth(MNotSet, mHeight: Height)
    }
}
